package com.itggm.controller;

import com.itggm.DTO.MessagePageDTO;
import com.itggm.pojo.Message;
import com.itggm.response.ResponseResult;


import com.itggm.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;


/**
 * @author: ggm
 * @data 2024年11月19日 10:32
 */
@RestController
@RequestMapping("message")
public class MessageController {


    @Autowired
    private MessageService messageService;

    @GetMapping("/page")
    public ResponseResult page(MessagePageDTO messagePageDTO){
        return messageService.page(messagePageDTO);

    }
    @GetMapping("delete")
    public ResponseResult  deleteMessages(Integer[] ids){
        List<Integer> listIds = Arrays.asList(ids);
        return messageService.delete(listIds) ;
    }

    @PostMapping("edit/{id}")
    public ResponseResult  editMessage(@PathVariable("id") Integer id){
        return messageService.editMessage(id) ;
    }

    @PostMapping("publish")
    public ResponseResult  publishMessage(Message message, @SessionAttribute("memberName") String memberName, @SessionAttribute("tel") String tel){

        message.setTel(tel);
        message.setMemberName(memberName);

        return messageService.publishMessage(message) ;
    }


}
